import datetime

class Playlist:
    def __init__(self, id, song_name, singer, href, word, create_time):
        self.id = id
        self.song_name = song_name
        self.singer = singer
        self.href = href
        self.word = word
        # self.create_time = create_time if create_time else datetime.now().strftime('%Y-%m-%d %H:%M:%S')
        self.create_time = create_time

    def to_dict(self):
        """将实体类的实例转换为一个字典，方便JSON序列化或数据库操作"""
        return {
            'id': self.id,
            'song_name': self.song_name,
            'singer': self.singer,
            'href': self.href,
            'word': self.word,
            'create_time': self.create_time
        }

    # 如果需要从字典创建实体类实例，可以添加一个类方法
    @classmethod
    def from_dict(cls, data):
        return cls(data['song_name'], data['singer'], data['href'], data.get('create_time'))

